package org.androidpush.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.androidpush.R;
import org.androidpush.greendao.NotificationMsg;

import java.util.List;
import java.util.Map;

/**
 * Created by huang on 2017/4/22 0022.
 */
public class MessAdapter extends BaseAdapter {

    private Context context;

    private List<NotificationMsg> datas;

    private LayoutInflater inflater;

    public MessAdapter(Context context, List<NotificationMsg> datas) {
        this.context = context;
        this.datas = datas;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vHolder = null;

        String title = (String) datas.get(position).getMsgTitle();
        String date = (String) datas.get(position).getMsgDate();
        String from = (String) datas.get(position).getMsgFrom();

        if (convertView == null) {
            vHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.xml_mess_item, null);
            vHolder.tv_title = (TextView) convertView
                    .findViewById(R.id.id_messitem_title);
            vHolder.tv_date = (TextView) convertView
                    .findViewById(R.id.id_messitem_time);
            vHolder.tv_from = (TextView) convertView.findViewById(R.id.id_messitem_from);
            convertView.setTag(vHolder);
        } else {
            vHolder = (ViewHolder) convertView.getTag();
        }
        vHolder.tv_title.setText(title);
        vHolder.tv_date.setText(date);
        vHolder.tv_from.setText(from);
        return convertView;
    }

    class ViewHolder {
        TextView tv_title, tv_date, tv_from;
    }
}
